package repository

import (
	"git.huoys.com/block_chain/mall/internal/user/repository/auth"
	"git.huoys.com/block_chain/mall/internal/user/repository/user"
	"git.huoys.com/block_chain/mall/pkg/database/redis"
	"git.huoys.com/block_chain/mall/pkg/log"
	"git.huoys.com/block_chain/mall/pkg/redisCache/temporaryCache"
	"gorm.io/gorm"
)

type userRepository struct {
	db  *gorm.DB
	log *log.Logger
	user.User
	auth.AuthRepo
}

type UserRepository interface {
	user.User
	auth.AuthRepo
	// 关闭数据库
	Close()
}

func NewRepository(db *gorm.DB, rd *redis.Client, log *log.Logger) (s UserRepository) {
	r := &userRepository{
		db:  db,
		log: log,
	}
	cache := temporaryCache.NewTemporaryCache(rd)
	r.User = user.NewUser(db, log, cache)
	r.AuthRepo = auth.NewAuthRepo(rd, log)
	return r
}

func (r *userRepository) Close() {}
